package com.qs.controller;


import com.qs.annotation.OperationLog;
import com.qs.pojo.dto.CommentDto;
import com.qs.pojo.entity.Comment;
import com.qs.response.Response;
import com.qs.service.ICommentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-11-25
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor
public class CommentController {

    private final ICommentService commentService;

    /**
     * 前台获取评价列表
     * @param goodsId
     * @return
     */
    @GetMapping("/list/{goodsId}")
    public Response listComments(@PathVariable("goodsId") Integer goodsId){
        log.info("前台获取评价列表请求进来--------");
        List<CommentDto> commentDto = commentService.listComments(goodsId);
        return Response.success(commentDto);
    }

    /**
     * 后台获取评价列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/backend/list/{pageNo}/{pageSize}/{userId}")
    public Response backendListComments(@PathVariable("pageNo") Integer pageNo,
                                        @PathVariable("pageSize") Integer pageSize,
                                        @PathVariable("userId") Integer userId){
        log.info("后台获取评价列表请求进来--------");
        Map<String,Object> map = commentService.backendListComments(pageNo, pageSize,userId);
        return Response.success(map);
    }

    /**
     * 保存评价内容请求进来
     * @param comment
     * @return
     */
    @PostMapping("/save")
    public Response saveComment(@RequestBody Comment comment){
        log.info("保存评价内容请求进来--------");
        commentService.saveComment(comment);
        return Response.success();
    }

}
